package com.itheima.array;

import com.itheima.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListDemo07 {
    public static void main(String[] args) {
        ArrayList<Student> list = getStudentList();
        ArrayList<Student> newList = getNewList(list);
        System.out.println("年龄低于18岁的成员:");
        for (int i = 0; i < newList.size(); i++) {
            System.out.println(newList.get(i).getName());
        }
    }

    public static ArrayList<Student> getStudentList() {
        Scanner sc = new Scanner(System.in);
        ArrayList<Student> list = new ArrayList<>();
        Student stu = new Student();
        System.out.println("输入成员信息,学号录入时,输入0结束录入");
        while (true) {
            System.out.println("请输入学号:");
            String sid = sc.next();
            if (sid.equals("0")) {
                System.out.println("录入结束");
                break;
            }
            System.out.println("请输入姓名:");
            String name = sc.next();
            System.out.println("请输入年龄:");
            int age = sc.nextInt();
            System.out.println("请输入分数:");
            double score = sc.nextInt();
            stu = new Student(sid, name, age, score);
            list.add(stu);
        }
        System.out.println("所有成员信息:");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getName() + "  " + list.get(i).getAge());
        }
        return list;
    }

    public static ArrayList<Student> getNewList(ArrayList<Student> list) {
        ArrayList<Student> newList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getAge() < 18)
                newList.add(list.get(i));
        }
        return newList;
    }
}
